package com.zHan.controller.utils;

import com.zHan.exception.BusinessException;
import com.zHan.exception.SystemException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * springmvc的异常处理器
 */
@RestControllerAdvice
public class ProjectExceptionAdvice {
    @ExceptionHandler(SystemException.class)
    public R doSystemException(SystemException ex){
        // 记录日志
        // 发生信息给运维
        // 发生邮件给开发人员
        System.out.println("出现业务异常");
        ex.printStackTrace();
        return new R(null,ex.getCode(),ex.getMessage());
    }

    @ExceptionHandler(BusinessException.class)
    public R doBusinessException(BusinessException ex){
        System.out.println("出现系统异常");
        ex.printStackTrace();
        return new R(null,ex.getCode(),ex.getMessage());
    }

    @ExceptionHandler(Exception.class)
    public R doException(Exception ex){
        // 记录日志
        // 发生信息给运维
        // 发生邮件给开发人员
        System.out.println("出现异常");
        ex.printStackTrace();
        return new R(null,CodeEnum.OTHER_ERR.code(),"系统繁忙，请稍后再试！");
    }
}
